package algorithms;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPool {

	List<Thread> threads;

	public ThreadPool() {
		threads = new ArrayList<Thread>();
	}

	public static void main(String[] args) {
		ExecutorService executor = new ThreadPoolExecutor(1, 2, 0L,
				TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());

		executor = Executors.newCachedThreadPool();
		
		executor.execute(new RunExample());
		executor.execute(new RunExample());

		executor.shutdown();

		while(!executor.isTerminated()) {}
		
		System.out.println("is termitated " + executor.isTerminated());
	}

	static class RunExample implements Runnable {

		@Override
		public void run() {
			// TODO Auto-generated method stub
			System.out.println(System.currentTimeMillis());
		}

	}

}
